// pages/cardRecord/cardRecord.js
var app = getApp();
var rootDocment = app.globalData.postUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 2,
    size:'10',
    page:'1',
    last_page:'0',
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    app.login(function (userInfo) {
      // wx.showLoading({
      //   title:'加载中',
      //   mask:true
      // })
      console.log('走这里了','============>',userInfo)
      that.setData({
        userInfo: userInfo
      });
      that.getRrecord()
     
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  onChange(event) {
    // wx.showToast({
    //   title: `切换到标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
    this.setData({
      active:event.detail.name
    })
    this.setData({
      page:'1',
      list:[]
    })
    this.getRrecord()
  },
  getRrecord(){
    wx.showLoading({
        title:'加载中',
        mask:true
      })
    let that = this
    var paraArr = new Array();
    paraArr['user_id'] = that.data.userInfo.userID;
    paraArr['size'] = that.data.size;
    paraArr['page'] = that.data.page;
    paraArr['status'] = that.data.active;
    var sign = app.signature(paraArr);
    wx.request({
      url: rootDocment + '/api/Redeem/record',
      data: {
        user_id:that.data.userInfo.userID,
        size:that.data.size,
        page:that.data.page,
        status:that.data.active,
        sign: sign
      },
      method: 'POST',
      header: {},
      success: function (res) {
        wx.hideLoading()
        if(res.data.code==1001){
          console.log(res)
          let oldList = that.data.list
          let newList = oldList.concat(res.data.data.data)
          that.setData({
            list:newList,
            last_page:res.data.data.last_page
          })
        }else{
          wx.showToast({
            title: res.data.msg,
          })
        }
        //console.log(res,'==============>getMiniappConfig')
       
      },
      fail:function(err){
        wx.hideLoading()
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
   
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    let page = Number(this.data.page) +1
    if(this.data.page==this.data.last_page){
      wx.showToast({
        title: '到底了',
        icon:'none'
      })
      return
    }
    this.setData({
      page:page,
    })
    this.getRrecord()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})